import { BasicColumn, FormSchema } from '@apps/antd-admin/src/components/table';
import { render } from '@apps/antd-admin/src/hooks/render/renderUtils';
import { vipcardList } from '@apps/ant-bus/src/views/business/goods/vipcard/data/api';
import { airportList } from '@apps/ant-bus/src/views/business/airport/data/api';
import { payWayList } from '@apps/ant-bus/src/views/business/platformManage/payway/data/api';
import { employeeList } from '@apps/ant-bus/src/views/business/employeeManage/employee/data/api';

export const columns: BasicColumn[] = [
  {
    title: '会员姓名',
    dataIndex: 'userName',
    width: 100,
  },
  {
    title: '手机号',
    dataIndex: 'userPhone',
    width: 120,
  },
  {
    title: '卡种名称',
    dataIndex: 'goodsName',
    width: 150,
  },
  {
    title: '状态',
    dataIndex: 'isCheck',
    width: 100,
    customRender: ({ record }: Recordable) => {
      const isCheckArray = [
        { label: '审核中', value: 1 },
        { label: '区域经理通过', value: 2 },
        { label: '财务人员通过', value: 3 },
        { label: '开卡成功', value: 4 },
      ];
      const isCheck: any = isCheckArray.find(item => item.value == record.isCheck);
      if (isCheck) {
        return isCheck.label;
      }
      return '';
    },
  },
  {
    title: '审核人',
    dataIndex: 'optUserName',
    width: 150,
  },
  {
    title: '来源',
    dataIndex: 'sourceType',
    width: 100,
    customRender: ({ record }: Recordable) => {
      const sourceTypeArray = [
        { label: '销售端新增', value: 1 },
        { label: '后台新增', value: 2 },
      ];
      const sourceType: any = sourceTypeArray.find(item => item.value == record.sourceType);
      if (sourceType) {
        return sourceType.label;
      }
      return '';
    },
  },
  {
    title: '开卡日期',
    dataIndex: 'startDate',
    width: 100,
  },

  {
    title: '销售姓名',
    dataIndex: 'employeeName',
    width: 100,
  },
  {
    title: '开卡地区',
    dataIndex: 'airportName',
    width: 100,
  },
  {
    title: '支付金额',
    dataIndex: 'amount',
    width: 100,
  },
  {
    title: '支付类型',
    dataIndex: 'payType',
    width: 100,
    customRender: ({ record }: Recordable) => {
      const payTypeArray = [
        { label: '迅联微信', value: 'PAY_WX' },
        { label: '易宝微信', value: 'PAY_WX_YIBAO' },
        { label: '银联微信', value: 'PAY_WX_YINLIAN' },
        { label: '农业银行微信', value: 'PAY_WX_NONGYE' },
        { label: '富友微信', value: 'PAY_WX_FUIOU' },
        { label: '富友微信小程序', value: 'PAY_WX_FUIOUP_MINI' },
        { label: '交通银行微信', value: 'PAY_WX_JIAOTONG' },
        { label: '支付宝', value: 'PAY_ALI' },
        { label: '线下', value: 'PAY_UNDERLINE' },
        { label: '公司余额', value: 'PAY_COMPANY_BALANCE' },
      ];
      const payType: any = payTypeArray.find(item => item.value == record.payType);
      if (payType) {
        return payType.label;
      }
      return '';
    },
  },
  {
    title: '收款凭证',
    dataIndex: 'voucherImg',
    width: 80,
    customRender: render.renderImage,
  },
  {
    title: '实体卡',
    dataIndex: 'isGive',
    width: 80,
    customRender: ({ record }: Recordable) => {
      const isGiveArray = [
        { label: '已给', value: 1 },
        { label: '未给', value: 2 },
      ];
      const isGive: any = isGiveArray.find(item => item.value == record.isGive);
      if (isGive) {
        return isGive.label;
      }
      return '';
    },
  },
  {
    title: '添加人',
    dataIndex: 'optUserName',
    width: 100,
  },
  {
    title: '创建日期',
    dataIndex: 'createTime',
    width: 150,
  },
  {
    title: '备注',
    dataIndex: 'checkRemark',
    width: 100,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'startDate',
    label: '开始日期',
    component: 'DatePicker',
    colProps: { span: 5 },
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
  {
    field: 'endDate',
    label: '结束日期',
    component: 'DatePicker',
    colProps: { span: 5 },
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
  {
    field: 'userInfo',
    label: '会员信息',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'goodsId',
    label: '卡种',
    component: 'ApiSelect',
    colProps: { span: 4 },
    componentProps: {
      api: vipcardList,
      params: { handlerName: 'busVipCardListHandler' },
      labelField: 'goodsName',
      valueField: 'goodsId',
      immediate: true,
      showSearch: true,
    },
  },
  {
    field: 'employeeId',
    label: '销售',
    component: 'ApiSelect',
    componentProps: {
      api: employeeList,
      params: { handlerName: 'busEmployeeListHandler' },
      labelField: 'employeeName',
      valueField: 'employeeId',
      immediate: true,
      showSearch: true,
    },
  },
  {
    field: 'airportId',
    label: '开卡地',
    component: 'ApiSelect',
    colProps: { span: 4 },
    componentProps: {
      api: airportList,
      params: { handlerName: 'busAirportRoleListHandler' },
      labelField: 'airportName',
      valueField: 'airportId',
      immediate: true,
      showSearch: true,
    },
  },
  {
    field: 'isCheck',
    label: '状态',
    component: 'Select',
    colProps: { span: 4 },
    componentProps: {
      options: [
        { label: '审核中', value: 1 },
        { label: '区域经理通过', value: 2 },
        { label: '开卡成功', value: 4 },
      ],
    },
  },
  {
    field: 'sourceType',
    label: '来源',
    component: 'Select',
    colProps: { span: 4 },
    componentProps: {
      options: [
        { label: '销售端', value: 1 },
        { label: '后台', value: 2 },
      ],
    },
  },
];

export const formSchema: FormSchema[] = [
  {
    label: '来源',
    field: 'sourceType',
    component: 'Input',
    required: true,
    defaultValue: 2,
    show: false,
  },
  {
    label: '会员姓名',
    field: 'userName',
    component: 'Input',
    required: true,
  },
  {
    label: '会员电话',
    field: 'userPhone',
    component: 'Input',
    required: true,
    /*rules: [
      { required: true, message: '请输入手机号' },
      { pattern: /^1[3456789]\d{9}$/, message: '手机号码格式错误！' },
    ],*/
  },
  {
    label: '卡种',
    field: 'goodsId',
    component: 'ApiSelect',
    required: true,
    componentProps: {
      api: vipcardList,
      params: { handlerName: 'busVipCardListHandler' },
      labelField: 'goodsName',
      valueField: 'goodsId',
      immediate: true,
      showSearch: true,
    },
  },
  {
    label: '开卡地',
    field: 'airportId',
    component: 'ApiSelect',
    required: true,
    componentProps: ({ formModel }) => {
      return {
        api: airportList,
        labelField: 'airportName',
        valueField: 'airportId',
        immediate: true,
        showSearch: true,
        onChange(airportId) {
          //formModel.employeeId = null;
        },
      };
    },
  },
  {
    label: '所属销售',
    field: 'employeeId',
    component: 'ApiSelect',
    required: false,
    componentProps: ({ formModel }) => {
      return {
        api: employeeList,
        params: { handlerName: 'busEmployeeListHandler', airportId: formModel.airportId },
        labelField: 'employeeName',
        valueField: 'employeeId',
        immediate: true,
        showSearch: true,
      };
    },
  },
  {
    label: '支付类型',
    field: 'payType',
    component: 'Select',
    required: true,
    componentProps: ({ formModel }) => {
      return {
        options: [{ label: '线下', value: 'PAY_UNDERLINE' }],
        onChange: payType => {
          console.info('payType', payType);
          formModel.paywayId = null;
        },
      };
    },
  },
  {
    label: '线下支付',
    field: 'paywayId',
    component: 'ApiSelect',
    required: false,
    componentProps: {
      api: payWayList,
      labelField: 'paywayName',
      valueField: 'paywayId',
      immediate: true,
      showSearch: true,
    },
    ifShow: ({ model }) => {
      if (model.payType == 'PAY_UNDERLINE') {
        return true;
      } else {
        return false;
      }
    },
  },
  {
    label: '实体卡',
    field: 'isGive',
    component: 'Select',
    required: true,
    defaultValue: 2,
    componentProps: {
      options: [
        { label: '已给', value: 1 },
        { label: '未给', value: 2 },
      ],
    },
  },
  {
    label: '开始时间',
    field: 'startDate',
    component: 'DatePicker',
    required: true,
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
    required: false,
  },
  {
    label: '收款凭证',
    field: 'voucherImg',
    component: 'ImageUpload',
    required: false,
  },
];

export const checkFormSchema: FormSchema[] = [
  {
    label: '新增会员记录Id',
    field: 'vipRecordId',
    component: 'Input',
    required: true,
    defaultValue: 2,
    show: false,
  },
  {
    label: '状态',
    field: 'isCheck',
    component: 'RadioGroup',
    required: true,
    defaultValue: 2,
    componentProps: {
      options: [
        { label: '通过', value: 2 },
        { label: '未通过', value: 3 },
      ],
    },
  },
  {
    label: '审核备注',
    field: 'checkRemark',
    component: 'InputTextArea',
    required: false,
  },
];

export const buZengFormSchema: FormSchema[] = [
  {
    label: '来源',
    field: 'sourceType',
    component: 'Input',
    required: true,
    defaultValue: 2,
    show: false,
  },
  {
    label: '会员姓名',
    field: 'userName',
    component: 'Input',
    required: true,
  },
  {
    label: '会员电话',
    field: 'userPhone',
    component: 'Input',
    required: true,
  },
  {
    label: '票务系统卡号',
    field: 'vipCardNo',
    component: 'Input',
    required: true,
  },
  {
    label: '卡种',
    field: 'goodsId',
    component: 'ApiSelect',
    required: true,
    componentProps: {
      api: vipcardList,
      params: { handlerName: 'busVipCardListHandler' },
      labelField: 'goodsName',
      valueField: 'goodsId',
      immediate: true,
      showSearch: true,
    },
  },
  {
    label: '开卡地',
    field: 'airportId',
    component: 'ApiSelect',
    required: true,
    componentProps: ({ formModel }) => {
      return {
        api: airportList,
        labelField: 'airportName',
        valueField: 'airportId',
        immediate: true,
        showSearch: true,
        onChange(airportId) {
          formModel.employeeId = null;
        },
      };
    },
  },
  {
    label: '所属销售',
    field: 'employeeId',
    component: 'ApiSelect',
    required: false,
    componentProps: ({ formModel }) => {
      return {
        api: employeeList,
        params: { handlerName: 'busEmployeeListHandler', airportId: formModel.airportId },
        labelField: 'employeeName',
        valueField: 'employeeId',
        immediate: true,
        showSearch: true,
      };
    },
  },
  {
    label: '支付类型',
    field: 'payType',
    component: 'Select',
    required: true,
    componentProps: ({ formModel }) => {
      return {
        options: [{ label: '线下', value: 'PAY_UNDERLINE' }],
        onChange: payType => {
          console.info('payType', payType);
          formModel.paywayId = null;
        },
      };
    },
  },
  {
    label: '线下支付',
    field: 'paywayId',
    component: 'ApiSelect',
    required: false,
    componentProps: {
      api: payWayList,
      labelField: 'paywayName',
      valueField: 'paywayId',
      immediate: true,
      showSearch: true,
    },
    ifShow: ({ model }) => {
      if (model.payType == 'PAY_UNDERLINE') {
        return true;
      } else {
        return false;
      }
    },
  },
  {
    label: '实体卡',
    field: 'isGive',
    component: 'Select',
    required: true,
    defaultValue: 2,
    componentProps: {
      options: [
        { label: '已给', value: 1 },
        { label: '未给', value: 2 },
      ],
    },
  },
  {
    label: '开始时间',
    field: 'startDate',
    component: 'DatePicker',
    required: true,
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
    required: false,
  },
  {
    label: '收款凭证',
    field: 'voucherImg',
    component: 'ImageUpload',
    required: false,
  },
];
